﻿using CardPlay.Model.ActionModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Actions;

namespace CardPlay.DemoPack.Games.FortyThievesVariants
{
    [Game("882FB93C-FB46-408E-89EC-51D549AA7E75", LevelOfDifficulty.Medium, LevelOfSkill.ModerateSkill, DurationOfPlay.MoreThan10Minutes, NumberOfDecks = 2, Family = FamilyName)]
    public class CarreNapoleon : NumberTen
    {
        public CarreNapoleon()
        {
            MaximumDeals = 2;
            TotalTableaus = 12;
            TableauDealFormat = "up";
            DealFoundationsInSetup = true;
        }

        protected override IAction QueryActionAt(PartLocation location)
        {
            var card = CardAt(location);

            if (card == null) return null;

            return location.Matches(Stock) && location.Index == this[Stock].TopIndex && TableauDealCount < 3
                ? CreateDealTableauAction(location)
                : base.QueryActionAt(location);
        }

        private int TableauDealCount { get; set; }

        private IAction CreateDealTableauAction(PartLocation location)
        {
            return new ComplexAction
            {
                new DealOutTableauAction(this, location),
                new DelegatingAction
                {
                    OnExecute = delegate { ++TableauDealCount; },
                    OnReverse = delegate { --TableauDealCount; }
                }
            };
        }
    }
}